package com.spring.springmvc.请求.传参;

import org.apache.logging.log4j.util.PropertiesUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/path")
public class 从路径中获取参数 {
    @RequestMapping("/r1/{name}")
    public String receive(@PathVariable("name") String name){
        return "接收到："+name;
    }
    @RequestMapping("/r1/{name}/{age}")
    public String receive(@PathVariable("name")String name,@PathVariable("age") Integer age){

        return "name:"+name+",age:"+age;
    }

    @RequestMapping("/r2/{name}/{age}")
    public String receive1(String name,@PathVariable("age") Integer age){

        return "name:"+name+",age:"+age;
    }
//    http://127.0.0.1:8080/path/r2/zhangsan/18?name=wangwu
}
/*
路径必须按照 @RequestMapping中的路径，如果没有@PathVariable("age")则无法从路径中获取
 */
